#include "MonkeyObject.h"
#include "MonkeyContext.h"



//
// Create a new MonkeyObject object in memory.
//
MonkeyObject::MonkeyObject()
{
}


//
// Destroy this MonkeyObject. Free all memory that needs to go away.
//
MonkeyObject::~MonkeyObject()
{
	//
	// Delete all child objects.
	//
	while (children.size() > 0)
	{
		MonkeyObject *obj = *children.begin();
		
		children.remove(obj);
		delete obj;
	}
}


//
// Retrieve the Javascript object for this object.
//
JSObject *MonkeyObject::jsObject()
{
	return object;
}


//
// Retrieve the MonkeyContext we are registered with.
//
MonkeyContext *MonkeyObject::Context()
{
	return context;
}


//
// Register this object with the parent object.
//
void MonkeyObject::RegisterObject(MonkeyContext *ctx, JSObject *parent)
{
	context = ctx;
}


//
// Add a new child object to this object.
//
void MonkeyObject::AddObject(MonkeyObject *obj)
{
	obj->RegisterObject(context, object);
	children.push_back(obj);
}

